unit F_ProductCoastInsert;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, JvExStdCtrls, JvEdit,
  JvValidateEdit, DB, ZAbstractRODataset, ZAbstractDataset, ZDataset;

type
  TProductCoastInsert = class(TForm)
    Panel_Inferior: TPanel;
    SB_Cancelar: TBitBtn;
    SB_Aceptarr: TBitBtn;
    Panel_PrecioCopia: TPanel;
    GB_Costos: TGroupBox;
    JvVE_Precio_Copia: TJvValidateEdit;
    ZQuery_UpdatePrice: TZQuery;
    ZQuery_Insert_Price: TZQuery;
    procedure SB_CancelarClick(Sender: TObject);
    procedure SB_AceptarrClick(Sender: TObject);
  private
    { Private declarations }
    procedure ActualizarCosto;
  public
    { Public declarations }
    idProducto: integer;
    constructor create(AOwner:Tcomponent; ProductID:integer);
  end;

implementation

uses DM_Persistencia, DateUtils;

{$R *.dfm}

constructor TProductCoastInsert.create(AOwner:Tcomponent; ProductID:integer);
begin
  inherited create(AOwner);
  idProducto:= ProductID;
end;

procedure TProductCoastInsert.ActualizarCosto;
begin
  with ZQuery_UpdatePrice do
    begin
      Close;
      Params.ParamByName('ID_PRODUCTO').Value:= idProducto;
      ExecSQL;
    end;

  with ZQuery_Insert_Price do
    begin
      Close;
      SQL.Clear;
      SQL.Add('INSERT INTO COSTO_PRODUCTO_FECHA (FK_ID_PRODUCTO, PRECIO) VALUES ('+IntToStr(idProducto)+', '+ StringReplace(FloatToStr(JvVE_Precio_Copia.Value),',','.',[rfReplaceAll, rfIgnoreCase])+') ');
      ExecSQL;
    end;
end;

procedure TProductCoastInsert.SB_CancelarClick(Sender: TObject);
begin
  Close;
  ModalResult:= mrCancel;
end;

procedure TProductCoastInsert.SB_AceptarrClick(Sender: TObject);
begin
  ActualizarCosto;
  ModalResult:= mrOk;
end;

end.
